<template>
  <div>
    <aplid-base-crud ref="crud" v-bind="baseConfig" @select="handleCurrentChange">
    </aplid-base-crud>
    <div class="btn_wrap">
      <el-button type="primary" @click="handleSave">保存</el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { baseConfig } from './config.js'
import { storeToRefs } from 'pinia'
import { useConfigStore } from '@/stores/common'
import { ElMessage } from 'element-plus'
import api from '@/apiMod'
const emit = defineEmits<{
  (e: 'close', data: Array<any>)
}>()
let { selection } = storeToRefs(useConfigStore())
selection.value = true
const selectList = ref([])
// const handleSelectChange = async (data) => {
//   selectList.value = data
// }
const handleCurrentChange = async (data, row) => {  
  selectList.value = data
  let checked: boolean
  const checkFilter = selectList.value.filter(item => item.id === row.id)
  if (checkFilter.length > 0) {
    checked = true
  } else {
    checked = false
  }
  if (checked) {
    const params = {
      // occupationType: 6,
      creditCode: row.creditCode,
      pageParaPO: {
        size: 10,
        current: 1
      }
    }
    const res = await api.view_dpFoundationPractitioners_page(params)
    if(res.data.records.length == 0){
      ElMessage.warning('该机构下没有从业人员')
    }
  }

}
const handleSave = () => {
  emit('close', selectList.value)
}
</script>

<style lang="scss" scoped>
.btn_wrap {
  display: flex;
  justify-content: flex-end;
}
</style>